package cn.doitedu.datayiee_service17.service;

import cn.doitedu.datayiee_service17.dao.SessionAgrDao;
import cn.doitedu.datayiee_service17.pojo.SessionAgrBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class SessionAgrServiceImpl implements SessionAgrService {

    @Autowired
    SessionAgrDao sessionAgrDao;

    @Override
    public List<SessionAgrBean> getSessions(Long ts,String startRow,int limit) throws Exception {

        List<HashMap<String, String>> sessions = sessionAgrDao.getSessions(ts, startRow, limit);

        ArrayList<SessionAgrBean> beanList = new ArrayList<>();
        for (HashMap<String, String> sessionMap : sessions) {
            SessionAgrBean bean = new SessionAgrBean();
            bean.setCity(sessionMap.get("city"));
            bean.setCountry(sessionMap.get("country"));
            bean.setDevice_type(sessionMap.get("device_type"));
            bean.setDt(sessionMap.get("dt"));
            bean.setEnd_ts(sessionMap.get("end_ts"));
            bean.setFirst_page_id(sessionMap.get("first_page_id"));
            bean.setGuid(sessionMap.get("guid"));
            bean.setHour_itv(sessionMap.get("hour_itv"));
            bean.setIsnew(sessionMap.get("isnew"));
            bean.setLast_page_id(sessionMap.get("last_page_id"));
            bean.setPv_cnt(sessionMap.get("pv_cnt"));
            bean.setRegion(sessionMap.get("region"));
            bean.setSession_id(sessionMap.get("session_id"));
            bean.setStart_ts(sessionMap.get("start_ts"));

            beanList.add(bean);
        }

        return beanList;
    }

}
